<template>
  <div class="page qrCodeDetail">
    <div class="scroll-view">
      <customHeader :middleTitle="$route.query.title||'查看收款二维码'" rightTitle="保存" @rightCallBack="saveImg"/>
      <div class="page-body">
        <img :src="imgUrl" class="qrImg" onerror="this.src='../../../static/images/no-data3.png'"/>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import customHeader from "../../components/header/header";
import { Toast, MessageBox } from "mint-ui";
import jsBridge from "../../tools/jsBridge";
export default {
  data() {
    return {
      shopId: 0,
      imgUrl: ""
    };
  },
  methods: {
    //保存图片
    saveImg() {
      try {
        jsBridge.savePicture({ url: this.imgUrl }, function (response) {
          if (response && (response.success === true || response.success === 'true')) {
            Toast("保存成功");
          } else {
            Toast("保存失败");
          }
        });
      } catch (e) {
        Toast("保存异常");
      }
    },
    loadData() {
      this.ajax({
        url: `/newapp/code/getQrCode.do?qrId=${this.$route.query.code}&shopId=${this.$route.query.shopId}`,
        type: "get",
        controlLoading: false
      })
        .then((res) => {
          if (res.success) {
            const data = res.resultObject;
            if (data != null && data !== "") {
              this.imgUrl = data;
            }
          } else {
            Toast(res.msg);
          }
        })
        .catch((err) => {
          Toast("获取二维码异常，请稍候重试");
        });
    }
  },
  created() {
    //this.loadData();
    this.imgUrl = this.$route.query.imgUrl;
  },
  components: {
    customHeader
  }
};
</script>
<style lang='scss' scoped>
@import "qrCodeDetail";
</style>
